package com.artPreter.service.impl;


import com.artPreter.mapper.DepartTypeMapper;
import com.artPreter.pojo.DepartType;
import com.artPreter.service.IDepartTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 机构分类表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2024-11-29
 */
@Service
public class DepartTypeServiceImpl extends ServiceImpl<DepartTypeMapper, DepartType> implements IDepartTypeService {

    @Override
    public IPage<DepartType> getPage(Integer currentPage, Integer size, DepartType departType) {
        LambdaQueryWrapper <DepartType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(departType.getName()!=null&&!"".equals(departType.getName())){
            lambdaQueryWrapper.like(DepartType::getName,departType.getName());
        }
        IPage<DepartType> departTypeIPage = new Page<>(currentPage,size);
        departTypeIPage = this.baseMapper.selectPage(departTypeIPage,lambdaQueryWrapper);
        return departTypeIPage;
    }

    @Override
    public void delete(DepartType departType) {
        if(departType.getId()!=null){
            this.baseMapper.deleteById(departType);
        }

    }

    @Override
    public List<DepartType> getList(DepartType departType) {
        LambdaQueryWrapper <DepartType> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(DepartType::getStatus,1);
        List<DepartType> departTypes = this.baseMapper.selectList(lambdaQueryWrapper);
        return departTypes;
    }

    @Override
    public void edit(DepartType departType) {
        if(departType.getId()!=null){
            this.baseMapper.updateById(departType);
        }

    }

    @Override
    public void add(DepartType departType) {
        String uuid = UUID.randomUUID().toString();
        departType.setTypeId(uuid);
        this.baseMapper.insert(departType);
    }
}
